package com.hengyue.common.core.service;

import com.hengyue.common.core.entity.BaseEntity;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import java.util.Optional;

public interface IBaseService<T extends BaseEntity, ID> {

    Iterable<T> findAll();

    Iterable<T> findAll(Sort sort);

    Page<T> findAll(Pageable pageable);

    Iterable<T> findAll(Specification<T> spec);

    Page<T> findAll(Specification<T> spec,Pageable pageable);

    Iterable<T> findAllById(Iterable<ID> ids);

    Optional<T> findById(ID id);

    <S extends T> Iterable<S> saveAll(Iterable<S> entities);

    <S extends T> Iterable<S> saveAllAndFlush(Iterable<S> entities);

    void flush();

    <S extends T> S saveAndFlush(S entity);

    <S extends T> S save(S entity);

    void delete(T entity);

    void deleteById(ID id);

    void deleteAll();

    void deleteAll(Iterable<T> list);

    void deleteAllByIdInBatch(Iterable<ID> list);

    boolean existsById(ID id);

    long count();

}
